module.exports = plop => {
  plop.setGenerator("app-components", {
    description: "创建全局组件模板",
    prompts: [
      {
        type: "input",
        name: "name",
        message: "请输入要创建的组件名称(必须以 app- 开头)",
        validate(value) {
          if (!value.length) return new Error("组件名称不能为空")
          if (!value.startsWith("app-")) return new Error("组件名称不合法")
          return true
        }
      },
      {
        type: "input",
        name: "cName",
        message: "组件中文名(十个字以内)：",
        validate(value) {
          const pass = value && value.length <= 10
          if (pass) return true
          return "不能为空，且不能超过十个字符"
        },
      },
      {
        type: "input",
        name: "desc",
        message: "组件描述(五十个字以内)：",
      },
      {
        type: "input",
        name: "author",
        message: "组件作者:",
        validate(value) {
          if (value) return true
          return "请把您的姓名或昵称留下！"
        },
      },
    ],
    actions: [
      {
        type: "add",
        path: "src/components/{{name}}/doc.md",
        templateFile: "script/componentTemplate/doc.md.hbs"
      },
      {
        type: "add",
        path: "src/components/{{name}}/index.scss",
        templateFile: "script/componentTemplate/index.scss.hbs"
      },
      {
        type: "add",
        path: "src/components/{{name}}/index.vue",
        templateFile: "script/componentTemplate/index.vue.hbs"
      }
    ]
  })
}